package com.tch.service;

import com.tch.async.MemberServiceAsync;
import jdk.nashorn.internal.ir.ReturnNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 */
@RestController
@Slf4j
public class MemberService {
    @Autowired
    private MemberServiceAsync memberServiceAsync;

    @RequestMapping("/addMember")
    public String addMember() {
        //第一步操作
        log.info(">01<");
        // 短信发送
//        new Thread(new Runnable() { //开一个Thread线程  不建议单独 new 一个线程
//            @Override
//            public void run() {
//                sms();
//            }
//        }).start();
//        sms();
        memberServiceAsync.sms();
        log.info(">04<");
        return "注册成功";
    }

//    @Async
//    public String sms(){
//        log.info(">02<");
//        log.info(">短信发送中。。。<");
//        try {
//            Thread.sleep(3000);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        log.info(">03<");
//        return "短息发送";
//    }

    /**
     *  演示系统出错
     * @param age
     * @return
     */
    @RequestMapping("/getException")
    public int getException(int age){
        int j = 1 / age ;
        return j;
    }
}
